package com.klun.concDesign.chapterFive.Future_5_5_3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class FutureMain {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 构造 FutureTask
        FutureTask<String> future = new FutureTask<>(new RealData("a"));
        ExecutorService executor = Executors.newFixedThreadPool(1);

        // 执行FutureTask
        executor.submit(future);

        System.out.println("请求完毕");
        try{
            // 用sleep代替业务操作
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 取得 call 方法的返回值
        System.out.println("数据 = " + future.get());

    }
}
